home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / DIALOG.PAK / DIALOG.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  262 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE: dialog.c
  9. //
  10. //  PURPOSE: Handles general routines for the dialog sample.
  11. //
  12. //  FUNCTIONS:
  13. //    WndProc - Processes messages for the main window.
  14. //    MsgCommand - Handle the WM_COMMAND messages for the main window.
  15. //    MsgDestroy   - Handles the WM_DESTROY message by calling 
  16. //                   PostQuitMessage().
  17. //    CmdModal     - Brings up the modal dialog
  18. //    CmdModeless  - Brings up the modeless dialog
  19. //    CmdExit      - Handles the file exit command by calling destory 
  20. //                   window on the main window.
  21. //
  22. //  COMMENTS:
  23. //
  24.  
  25. #include <windows.h>            // required for all Windows applications
  26. #include <windowsx.h>
  27. #ifdef WIN16
  28. #include "win16ext.h"           // required only for win16 applications
  29. #endif
  30. #include "globals.h"            // prototypes specific to this application
  31. #include "modal.h"
  32. #include "modeless.h"
  33. #include "resource.h"
  34.  
  35. // Main window message table definition.
  36. MSD rgmsd[] =
  37. {
  38.     {WM_COMMAND, MsgCommand},
  39.     {WM_DESTROY, MsgDestroy},
  40.     {WM_PAINT,   MsgPaint}       //For ecapsulation purposes, this is in
  41.                                  //modeless.c
  42. };
  43.  
  44. MSDI msdiMain =
  45. {
  46.     sizeof(rgmsd) / sizeof(MSD),
  47.     rgmsd,
  48.     edwpWindow
  49. };
  50.  
  51.  
  52. // Main window command table definition.
  53. CMD rgcmd[] =
  54. {
  55.     {IDM_EXIT,     CmdExit},
  56.     {IDM_MODAL,    CmdModal},
  57.     {IDM_MODELESS, CmdModeless},
  58.     {IDM_ABOUT,    CmdAbout}
  59. };
  60.  
  61. CMDI cmdiMain =
  62. {
  63.     sizeof(rgcmd) / sizeof(CMD),
  64.     rgcmd,
  65.     edwpWindow
  66. };
  67.  
  68.  
  69. //
  70. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  71. //
  72. //  PURPOSE:  Processes messages for the main window.
  73. //
  74. //  PARAMETERS:
  75. //    hwnd     - window handle
  76. //    uMessage - message number
  77. //    wparam   - additional information (dependant on message number)
  78. //    lparam   - additional information (dependant on message number)
  79. //
  80. //  RETURN VALUE:
  81. //    The return value depends on the message number.  If the message
  82. //    is implemented in the message dispatch table, the return value is
  83. //    the value returned by the message handling function.  Otherwise,
  84. //    the return value is the value returned by the default window procedure.
  85. //
  86. //  COMMENTS:
  87. //    Call the DispMessage() function with the main window's message dispatch
  88. //    information (msdiMain) and the message specific information.
  89. //
  90.  
  91. LRESULT CALLBACK WndProc(HWND   hwnd, 
  92.                          UINT   uMessage, 
  93.                          WPARAM wparam, 
  94.                          LPARAM lparam)
  95. {
  96.     return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
  97. }
  98.  
  99.  
  100. //
  101. //  FUNCTION: MsgCommand(HWND, UINT, WPARAM, LPARAM)
  102. //
  103. //  PURPOSE: Handle the WM_COMMAND messages for the main window.
  104. //
  105. //  PARAMETERS:
  106. //    hwnd     - window handle
  107. //    uMessage - WM_COMMAND (Unused)
  108. //    GET_WM_COMMAND_ID(wparam,lparam)   - Command identifier
  109. //    GET_WM_COMMAND_HWND(wparam,lparam) - Control handle
  110. //
  111. //  RETURN VALUE:
  112. //    The return value depends on the message number.  If the message
  113. //    is implemented in the message dispatch table, the return value is
  114. //    the value returned by the message handling function.  Otherwise,
  115. //    the return value is the value returned by the default window procedure.
  116. //
  117. //  COMMENTS:
  118. //    Call the DispCommand() function with the main window's command dispatch
  119. //    information (cmdiMain) and the command specific information.
  120. //
  121.  
  122. #pragma argsused
  123. LRESULT MsgCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  124. {
  125.     return DispCommand(&cmdiMain, hwnd, wparam, lparam);
  126. }
  127.  
  128.  
  129. //
  130. //  FUNCTION: MsgDestroy(HWND, UINT, WPARAM, LPARAM)
  131. //
  132. //  PURPOSE: Calls PostQuitMessage().
  133. //
  134. //  PARAMETERS:
  135. //
  136. //    hwnd      - Window handle  (Unused)
  137. //    uMessage  - Message number (Unused)
  138. //    wparam    - Extra data     (Unused)
  139. //    lparam    - Extra data     (Unused)
  140. //
  141. //  RETURN VALUE:
  142. //
  143. //    Always returns 0 - Message handled
  144. //
  145. //  COMMENTS:
  146. //
  147. //
  148.  
  149. #pragma argsused
  150. LRESULT MsgDestroy(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
  151. {
  152.      PostQuitMessage(0);
  153.      return 0;
  154. }
  155.  
  156. //
  157. //  FUNCTION: CmdModal(HWND, WORD, WORD, HWND)
  158. //
  159. //  PURPOSE: Displays the "Modal" dialog box
  160. //
  161. //  PARAMETERS:
  162. //    hwnd      - Window handle
  163. //    wCommand  - IDM_ABOUT (unused)
  164. //    wNotify   - Notification number (unused)
  165. //    hwndCtrl  - NULL (unused)
  166. //
  167. //  RETURN VALUE:
  168. //
  169. //    Always returns 0 - Message handled
  170. //
  171. //  COMMENTS:
  172. //    To process the IDM_ABOUT message, call MakeProcInstance() to get the
  173. //    current instance address of the Modal() function.  Then call Dialog
  174. //    box which will create the box according to the information in your
  175. //    sample.rc file and turn control over to the Modal() function.  When
  176. //    it returns, free the intance address.
  177. //
  178. //
  179.  
  180. #pragma argsused
  181. LRESULT CmdModal(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  182. {
  183.     DLGPROC lpProcModal = MakeProcInstance((FARPROC)Modal, hInst);
  184.  
  185.     DialogBox(hInst, MAKEINTRESOURCE(IDD_MODALDIALOG), hwnd, lpProcModal);
  186.  
  187. #ifdef _ _WIN32_ _
  188.      FreeProcInstance(lpProcModal);
  189. #endif
  190.  
  191.      return 0;
  192. }
  193.  
  194.  
  195. //
  196. //  FUNCTION: CmdModeless(HWND, WORD, WORD, HWND)
  197. //
  198. //  PURPOSE: Displays the "Modeless" dialog box
  199. //
  200. //  PARAMETERS:
  201. //    hwnd      - Window handle
  202. //    wCommand  - IDM_ABOUT (unused)
  203. //    wNotify   - Notification number (unused)
  204. //    hwndCtrl  - NULL (unused)
  205. //
  206. //  RETURN VALUE:
  207. //
  208. //    Always returns 0 - Message handled
  209. //
  210. //  COMMENTS:
  211. //    To process the IDM_ABOUT message, call MakeProcInstance() to get the
  212. //    current instance address of the Modeless() function.  Then call Dialog
  213. //    box which will create the box according to the information in your
  214. //    sample.rc file and turn control over to the Modeless() function.  When
  215. //    it returns, free the intance address.
  216. //
  217. //
  218.  
  219. #pragma argsused
  220. LRESULT CmdModeless(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  221. {
  222.     if (!lpProcModeless && !hwndModeless)
  223.     {
  224.         lpProcModeless = MakeProcInstance((FARPROC)Modeless, hInst);
  225.  
  226.         hwndModeless = CreateDialog(hInst, 
  227.                                     MAKEINTRESOURCE(IDD_MODELESSDIALOG), 
  228.                                     hwnd, 
  229.                                     lpProcModeless);
  230.     }
  231.     else
  232.         SetActiveWindow(hwndModeless);
  233.  
  234.     return 0;
  235. }
  236.  
  237.  
  238. //
  239. //  FUNCTION: CmdExit(HWND, WORD, WORD, HWND)
  240. //
  241. //  PURPOSE: Exit the application.
  242. //
  243. //  PARAMETERS:
  244. //    hwnd     - The window.
  245. //    wCommand - IDM_EXIT (unused)
  246. //    wNotify  - Notification number (unused)
  247. //    hwndCtrl - NULL (unused)
  248. //
  249. //  RETURN VALUE:
  250. //    Always returns 0 - command handled.
  251. //
  252. //  COMMENTS:
  253. //
  254. //
  255.  
  256. #pragma argsused
  257. LRESULT CmdExit(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  258. {
  259.      DestroyWindow(hwnd);
  260.      return 0;
  261. }
  262.